<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no"/>
<link href="css/reset.css" rel="stylesheet" type="text/css">
<link href="css/discounts.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="near-box">
      <!--头部开始-->
	  <div class="header"  id="headerTxt">
	  	 <a href="index.html" class="left"></a>

	  </div>
	  <!--头部结束-->
      <div class="discounts-bigbox">
		  <div class="discounts-banner1"><img src="del/discounts-img1.jpg" alt=""></div>

      </div>

      
</div>
<script src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/scrolltopcontrol.js"></script>
<script type="text/javascript" src="js/core.util.js"></script>
<script type="text/javascript" src="js/mlayer.min.js"></script>

<script>
$(function(){
	var url=window.location.search; //获取url中"?"符后的字串
	var catId = url.substr(url.indexOf("=")+1);
	if(catId == 30) {
		$("#headerTxt").append("果篮礼盒");
	} else if(catId == 28) {
		$("#headerTxt").append("干果果汁");
	} else if(catId == 25) {
		$("#headerTxt").append("西瓜蜜瓜");
	} else if(catId == 26) {
		$("#headerTxt").append("葡提浆果");
	}
	var index = mlayer.loading({
		title: '加载中'
	});
	CoreUtil.sendPost("/api/index/getProductByCateId", {"catId":catId},function (res) {
		if(res.code ==  200) {
			var content = "";
			for(var imvos of res.data.productVoList) {
				content+="<div class='discounts-box1'>";
					content+="<a href='goods-details.html?productId="+imvos.id+"'><span class='d-box1-img1'><img src='"+imvos.imgUrl+"' alt=''></span></a>";
						content+="<div class='discounts-box2'>";
							content+="<span class='d-box2-text1'>"+imvos.productName+"</span>";
							content+="<span class='d-box2-text2'>￥"+imvos.mallMobilePrice+" </span>";
						content+="<button class='d-box2-btn buynow' productId="+imvos.id+">立即购买</button>";
					content+="</div>";
				content+="</div>";
			}
			$(".discounts-banner1").append(content)
		} else {
			mlayer.error({
				title: res.msg,
				time: 3
			});
		}
		mlayer.close(index);
	});

	$(".discounts-bigbox").on("click",".buynow",function() {
		var member = localStorage.getItem("member");
		if(member==null) {
			mlayer.alert({
				title: '消息',
				content: '请先去登录',
				btn:['不了', 'OK'],
				yes: function(index) {
					location.href = "login.html";
				}
			});
			return;
		}
		var productId = $(this).attr("productId");
		CoreUtil.sendPost("/api/cart/addCart",{"memberMobile":JSON.parse(member).mobile,"productId":productId,"number":1},function (res) {
			if(res.code ==  200) {
				location.href = "order.html?productId=" + productId;
			} else {
				mlayer.error({
					title: res.msg,
					time: 3
				});
			}
		})
	});
});
</script>
</body>
</html>